def proverka(n):
    d = 0
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            d+=1
    if d ==0:
        return 1
    else:
        return 0
b = input()
n = 0
for l in range(0,4):
    for i in range(4,0,-1):
        if i>l:
            if proverka(int(b[l:i]))==1:
                if int(b[l:i])>n:
                    n=int(b[l:i])
print(n)
